package com.sias.view;

import com.sias.bean.Emp;
import com.sias.service.EmpService;
import com.sias.service.impl.EmpServiceImpl;
import com.sun.deploy.panel.DeleteFilesDialog;
import com.sun.xml.internal.bind.v2.model.core.ID;
import org.junit.Test;
import sun.awt.util.IdentityLinkedList;

import java.sql.Date;
import java.util.List;
import java.util.Scanner;

/**
 * 此类为员工管理系统程序入口类
 **/
public class Entrance {
    static  Scanner sc = new Scanner(System.in);
    static EmpService empService=new EmpServiceImpl();
    /**
     * 程序启动入口
     */
    public static void main(String [] args) {
        System.out.println("======================================");
        System.out.println("======********员工管理系统********=======");
        System.out.println("======================================");
        menu();
    }

    /**
     * 程序欢迎菜单
     */
    private static void menu() {
        System.out.println("请输入相应操作序号:1.员工列表 2.增加员工 3.修改员工信息 4.删除员工 5.根据员工姓名模糊查询 6.退出");
        int num=sc.nextInt();
        switch (num) {
            case 1:
                //员工列表
                List<Emp> empList = empService.getAllEmp();
                for (Emp emp : empList) {
                    System.out.println(emp);
                }
                break;
            case 2:
                //添加员工，调用方法
               Entrance.add1();
                break;
            case 3:
                System.out.println("请输入你要修改员工的工号：");
                int empno=sc.nextInt();
                empService.upDate(empno);
                break;
            case 4:
                System.out.println("请输入你要删除员工的编号：");
                int empon= sc.nextInt();
                empService.delEmpById(empon);
                break;
            case 5:
                System.out.print("输入名字关键字，进行模糊查询：");
                String ename = sc.next();
                List<Emp> empList5 = empService.selectLikeName(ename);
                for (Emp emp : empList5) {
                    System.out.println(emp);
                }
                break;
            case 6:
                //退出
                System.exit(0);
                break;
        }
    }

    //添加员工方法
    public static void add1(){
        Emp emp = new Emp();
        System.out.println("输入名字:");
        String ename = sc.next();
        emp.setEname(ename);

        System.out.println("输入工作:");
        String job = sc.next();
        emp.setJob(job);

        System.out.println("输入薪资:");
        double sal = sc.nextDouble();
        emp.setSal(sal);
        //写入当前系统时间
        Date date = new Date((new java.util.Date().getTime()));
        emp.setHiredate(date);

        System.out.println("输入奖金:");
        double comm = sc.nextDouble();
        emp.setComm(comm);

        System.out.println("输入部门编号:");
        int deptno = sc.nextInt();
        emp.setDeptno(deptno);

        empService.addEmp(emp);
    }
}
